/*******************************************************************************
 * Copyright (c) 2012 Clever Devices.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl.html
 * 
 * Contributors:
 * 	Clever Devices Interns - 
 * 	Alex Frankel, Andria Young, Kevin Thomas, Nicholas Culpepper, Taner Oztimurlenk, Thomas Volberg
 ******************************************************************************/
package com.framework.cleverstop_tentative;

import android.app.Activity;
import android.content.Intent;
import android.nfc.NdefMessage;
import android.nfc.NfcAdapter;
import android.os.Bundle;
import android.os.Parcelable;

/**
 * 
 * @author KThomas
 * 
 * Handles the NFC tag information that is picked up from the tag and launches
 * the appropriate activity. Responds to plain text tags with "faretag" and
 * "starbucks" written onto it. 
 */
public class NFCActivityChooser extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
		// PARSING THE TAG DATA
		Parcelable[] rawmsgs = getIntent().getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);	//get the raw NFC 
		NdefMessage msg = (NdefMessage)rawmsgs[0];	// convert the raw parcelable message to NdefMessage type
		String tagID = new String(msg.getRecords()[0].getPayload());	// get the payload from the NdefMessage and convert to a string tagID
		tagID = tagID.substring(3, 10);	// the first three and last few characters in the string are nonsense
		System.out.println(tagID);	// print the tagID for testing
        
		if(tagID.equalsIgnoreCase("faretag")){	//if "faretag" is found
			Intent fareActivity = new Intent("com.framework.fares.FAREPAYMENTACTIVITY");	//launch fare payment activity
			startActivity(fareActivity);
		}
		if(tagID.equalsIgnoreCase("starbuc")){	//if "starbuc" is found
			Intent fareActivity = new Intent("com.framework.cleverstop_tentative.STARBUCKSREWARD");	//launch starbucks reward activity
			startActivity(fareActivity);
		}
		finish();	//finish the activity's lifecycle
    }
    
}
